package com.gcosc.hly.codejava.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gcosc.hly.codejava.entity.Answer;
import com.gcosc.hly.codejava.entity.AnswerItem;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface AnswerItemMapper extends BaseMapper<AnswerItem> {

    @Select("select IFNULL(sum(b.`level`), 0) a from answer_item a LEFT JOIN topic b" +
            " on a.topic_id = b.id WHERE a.answer_id = #{id} and a.result = 1")
    int countFraction(int id);


//    @Select("select IFNULL(sum(b.`level`), 0) a from answer_item a LEFT JOIN topic b" +
//            " on a.topic_id = b.id WHERE a.answer_id = #{id}")
    @Select("SELECT count_fraction from paper WHERE id = (SELECT paper_id from answer WHERE id = #{id})")
    int countMaxFraction(int id);
}
